<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">		
	$(function() {
		parent.$.messager.progress('close');
		 $('#role-ul').tree({
			data : JSON.parse('${role}'),
			checkbox : true,
			onLoadSuccess : function(){
				try{
					var idstr = '${user.roleIds}';
					var ids = idstr.split(',');
					for(var key in ids){
						var node = $('#role-ul').tree('find',ids[key]);
						if(node){
							$('#role-ul').tree('check',node.target);
						}
					}
				} catch(e){}
			}
		});
		
		$('#form').form({
			url : '/userController/edit',
			onSubmit : function() {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				var isValid = $(this).form('validate');
				if (!isValid) {
					parent.$.messager.progress('close');
				}
				
				//设置角色
				var roleNodes = $('#role-ul').tree('getChecked');
				var roleids = '';
				for(var i=0 ;i<roleNodes.length;i++){
					if(roleids != ''){
						roleids += ',';
					}
					roleids += roleNodes[i].id;
				}
				$("form input[name='roleIds']").val(roleids);
				return isValid;
			},
			success : function(result) {
				try{
					parent.$.messager.progress('close');
					result = $.parseJSON(result);
					if (result.success) {
						parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
						parent.$.modalDialog.handler.dialog('close');
					} else {
						parent.$.messager.alert('错误', result.msg, 'error');
					}
				} catch(e){
						parent.$.messager.alert('错误', result, 'error');
				}
			}
		});
	});
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" title="" style="overflow: hidden;">
		<form id="form" method="post" style="overflow: auto;height: 100%">
			<input name="id" type="hidden" class="span2" value="${user.id}" readonly="readonly">
			<input name="employeeId" type="hidden" class="span2" value="${user.employeeId}" readonly="readonly">
			<input name="roleIds" type="hidden" class="span2" value="${user.roleIds}" readonly="readonly">
			
			<table class="table table-hover table-condensed">
				<tr>
					<th>登录名称</th>
					<td><input name="loginName" type="text" placeholder="请输入登录名称" class="easyui-validatebox span2" data-options="required:true" value="${user.loginName }" readonly="readonly"></td>
				</tr>
				<tr>
					<th>密码</th>
					<td><input name="loginPwd" type="password" placeholder="请输入密码" class="easyui-validatebox span2" data-options="required:true" value="******" readonly="readonly"></td>
				</tr>
				<tr>
					<th>选择员工</th>
					<td>
						<input type="text" readonly="readonly"  value="${user.employeeName }"/> 
					</td>
				</tr>
				<tr>
					<th>选择角色</th>
					<td>
						<ul id="role-ul"></ul>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>